<template>
  <div class="playController">
    <div class="left" @click="show = !show">
      <img :src="playlist[playCurrentIndex].al.picUrl" alt="" />
      <div class="content">
        <div class="title">{{ playlist[playCurrentIndex].al.name }}</div>
        <div class="tips">横滑可以切换上下首</div>
      </div>
    </div>
    <div class="right">
      <svg v-if="paused" class="icon" aria-hidden="true" @click="play">
        <use xlink:href="#icon-24gl-play"></use>
      </svg>
      <svg v-else class="icon" aria-hidden="true" @click="play">
        <use xlink:href="#icon-24gl-pause"></use>
      </svg>
      <svg class="icon" aria-hidden="true">
        <use xlink:href="#icon-liebiao"></use>
      </svg>
    </div>
    <play-music
      :play="play"
      :paused="paused"
      @back="show = !show"
      v-show="show"
      :playDetail="playlist[playCurrentIndex]"
    ></play-music>
    <!-- <audio controls :src="`https://music.163.com/song/media/outer/url?id=${playlist[playCurrentIndex].id}.mp3`"></audio> -->
    <audio
      ref="audio"
      :src="
        `https://music.163.com/song/media/outer/url?id=${playlist[playCurrentIndex].id}.mp3`
      "
    ></audio>
  </div>
</template>

<script>
import playMusic from "@/components/playMusic.vue";
import { mapState } from "vuex";
export default {
  data() {
    return {
      paused: true,
      show: false,
    };
  },
  computed: {
    ...mapState(["playlist", "playCurrentIndex"]),
  },
  mounted() {
    this.$store.dispatch("reqLyric", {
      id: this.playlist[this.playCurrentIndex].id,
    });
  },
  updated() {
    this.$store.dispatch("reqLyric", {
      id: this.playlist[this.playCurrentIndex].id,
    });

  },
  methods: {
    play: function() {
      if (this.$refs.audio.paused) {
        this.$refs.audio.play();
        this.paused = false;
        this.UpdateTime();
      } else {
        this.$refs.audio.pause();
        this.paused = true;
        clearInterval(this.$store.state.id);
      }
    },
    UpdateTime() {
      this.$store.state.id = setInterval(() => {
        this.$store.commit("setCurrentTime", this.$refs.audio.currentTime);
      }, 1000);
    },
  },
  components: {
    playMusic,
  },
};
</script>

<style lang="less" scoped>
.playController {
  width: 7.5rem;
  height: 1.2rem;
  padding: 0 0.05rem;
  background: #fff;
  position: fixed;
  left: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #ccc;
  .left {
    display: flex;
    padding: 0 0.2rem;
    img {
      width: 0.8rem;
      height: 00.8rem;
      border-radius: 00.4rem;
    }
    .content {
      padding: 0 0.2rem;
      .title {
        display: -webkit-inline-flex;
        width: 4.2rem;
        height: 0.4rem;
        overflow: hidden;
      }
      .tips {
        font-size: 00.2rem;
        color: #999;
      }
    }
  }
  .right {
    .icon {
      margin: 0 0.2rem;
      width: 0.4rem;
      height: 00.4rem;
    }
  }
}
</style>
